public class Text {
    public static void main(String[] args) {
        Master master = new Master();
        master.feedDog("骨头");
        master.feedCat("鱼");
    }
}
class Master {
    private Pet mPet;
    private Food mFood;
    public void feedCat(String food) {
        mPet = new Cat();
        mFood = new Food(food);
        mPet.eat(mFood);
    }
    public void feedDog(String food) {
        mPet = new Dog();
        mFood = new Food(food);
        mPet.eat(mFood);
    }
}
class Dog extends Pet {

    public void eat(Food food) {
        System.out.println("喂旺财吃"+food.getFood());
        if (food.getFood().matches(Food.BONE)) {
            System.out.println("旺财吃"+food.getFood());
        }else {
            System.out.println("但是旺财不喜欢吃"+food.getFood());
        }
    }
}
class Cat extends Pet {

    public void eat(Food food) {
        System.out.println("喂小花吃"+food.getFood());
        if (food.getFood().matches(Food.FISH)) {
            System.out.println("小花吃"+food.getFood());
        }else {
            System.out.println("但是小花不喜欢吃"+food.getFood());
        }
    }
}
class Food {
    public final static String BONE = ".*骨头.*";
    public final static String FISH = ".*鱼.*";
    private String food;
    public String getFood() {
        return food;
    }
    public void setFood(String food) {
        this.food = food;
    }
    public Food(String food) {
        this.food = food;
    }
}
class Pet {
    public void eat(Food food) {

    }
}
